<h1>Django Templates</h1>

<h2>NOTES</h2>

<ul>
<li>The name should map to the URL.</li>
<li>No distro or app name prefix, they are namespaced by their dirs already</li>
<li>Since templates are made in python, the are <code>named_with_underscores.html</code> (not web style dashes).</li>
</ul>

<h2>URL PARAMETERS IN THE TEMPLATE</h2>

<ul>
<li>All views (except <code>generic.View</code>) from <code>django.forms.generic</code> inherit from <code>ContextMixin</code></li>
<li><p><code>ContextMixin</code> defines the method <code>get_context_data</code>:</p>

<div class="codehilite">
<pre><span></span><code><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">kwargs</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s1">&#39;view&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">extra_context</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">kwargs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">extra_context</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">kwargs</span>
</code></pre>
</div>

<p>So when overriding one must be careful to extends <code>super</code>'s <code>kwargs</code>:</p>

<div class="codehilite">
<pre><span></span><code><span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="n">kwargs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;page_title&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;Documentation&quot;</span>
    <span class="k">return</span> <span class="n">kwargs</span>
</code></pre>
</div></li>
</ul>
